#! /bin/sh

mkdir -p out || exit 99

name=$( basename "$0" )
datafile="$srcdir/${name}.data"
dumpfile="out/${name}.dump"
resultfile="out/${name}.result"
expectfile="$srcdir/${name}.expect"

./mkelf "$dumpfile" <<EOF
ei_class = 2
ei_data = 1
e_machine = 243
e_phoff = 0x1000

DATA = $datafile
EOF
rc=$?
if [ $rc -ne 0 ]; then
    echo "Cannot create ELF file" >&2
    exit $rc
fi
echo "Created ELF dump: $dumpfile"

./checkattr "$dumpfile" <<EOF
file = directory:
file.set.number = number:1
file.set.0 = directory:
file.set.0.fd = number
file.format = string: elf

cpu = directory:
cpu.number = number:1
cpu.0 = directory:
cpu.0.PRSTATUS = blob:\
0300000004000000050000000b000000\
70725f736967706570725f736967686f\
5f70696470706964706772705f736964\
000000000000000070725f7574696d65\
000000000000000070725f7374696d65\
000000000000000070725f637574696d\
000000000000000070725f637374696d\
20202020202070632020202020207261\
20202020202073702020202020206770\
20202020202074702020202020207430\
20202020202074312020202020207432\
20202020202073302020202020207331\
20202020202061302020202020206131\
20202020202061322020202020206133\
20202020202061342020202020206135\
20202020202061362020202020206137\
20202020202073322020202020207333\
20202020202073342020202020207335\
20202020202073362020202020207337\
20202020202073382020202020207339\
20202020207331302020202020733131\
20202020202074332020202020207434\
20202020202074352020202020207436\
0000000000000000
cpu.0.reg = directory:
cpu.0.reg.pc  = number:0x6370202020202020
cpu.0.reg.ra  = number:0x6172202020202020
cpu.0.reg.sp  = number:0x7073202020202020
cpu.0.reg.gp  = number:0x7067202020202020
cpu.0.reg.tp  = number:0x7074202020202020
cpu.0.reg.t0  = number:0x3074202020202020
cpu.0.reg.t1  = number:0x3174202020202020
cpu.0.reg.t2  = number:0x3274202020202020
cpu.0.reg.s0  = number:0x3073202020202020
cpu.0.reg.s1  = number:0x3173202020202020
cpu.0.reg.a0 = number:0x3061202020202020
cpu.0.reg.a1 = number:0x3161202020202020
cpu.0.reg.a2 = number:0x3261202020202020
cpu.0.reg.a3 = number:0x3361202020202020
cpu.0.reg.a4 = number:0x3461202020202020
cpu.0.reg.a5 = number:0x3561202020202020
cpu.0.reg.a6 = number:0x3661202020202020
cpu.0.reg.a7 = number:0x3761202020202020
cpu.0.reg.s2 = number:0x3273202020202020
cpu.0.reg.s3 = number:0x3373202020202020
cpu.0.reg.s4 = number:0x3473202020202020
cpu.0.reg.s5 = number:0x3573202020202020
cpu.0.reg.s6 = number:0x3673202020202020
cpu.0.reg.s7 = number:0x3773202020202020
cpu.0.reg.s8 = number:0x3873202020202020
cpu.0.reg.s9 = number:0x3973202020202020
cpu.0.reg.s10 = number:0x3031732020202020
cpu.0.reg.s11 = number:0x3131732020202020
cpu.0.reg.t3 = number:0x3374202020202020
cpu.0.reg.t4 = number:0x3474202020202020
cpu.0.reg.t5 = number:0x3574202020202020
cpu.0.reg.t6 = number:0x3674202020202020
cpu.0.pid = number:0x6469705f
EOF
rc=$?
if [ $rc -ne 0 ]; then
    echo "Attribute check failed" >&2
    exit $rc
fi

exit 0
